package com.ycy.temperature.view.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.AutoCompleteTextView;
import android.widget.TextView;

import com.airsaid.pickerviewlibrary.OptionsPickerView;
import com.jude.utils.JUtils;
import com.qmuiteam.qmui.util.QMUIStatusBarHelper;
import com.ycy.temperature.R;
import com.ycy.temperature.bean.VerificationBean;
import com.ycy.temperature.bean.ＭeBean;
import com.ycy.temperature.date.net.UserNetWorks;
import com.ycy.temperature.date.utils.CheckUtils;
import com.ycy.temperature.view.base.BaseActivity;
import com.ycy.temperature.view.view.TitleView;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import rx.Subscriber;

/**
 * Created by MI on 2018/7/17.
 */

public class OtherActivity extends BaseActivity {
    @BindView(R.id.title)
    TitleView title;
    @BindView(R.id.Text_Height)
    AutoCompleteTextView TextHeight;
    @BindView(R.id.Text_Monthincome)
    AutoCompleteTextView TextMonthincome;
    @BindView(R.id.Text_Weight)
    AutoCompleteTextView TextWeight;
    @BindView(R.id.Text_Smoke)
    TextView TextSmoke;
    @BindView(R.id.Text_Drinkwine)
    TextView TextDrinkwine;
    @BindView(R.id.Text_Symbolicanimals)
    TextView TextSymbolicanimals;
    @BindView(R.id.Text_Religion)
    TextView TextReligion;

    private OptionsPickerView<String> mOptionsPickerView;

    private ArrayList<String> MarriageList = new ArrayList<String>();
    private ArrayList<String> ChildrenList = new ArrayList<String>();
    private ArrayList<String> CurrencyList = new ArrayList<String>();
    private ArrayList<String> ZodiacyList = new ArrayList<String>();

    @Override
    protected int getLayout() {
        return R.layout.activity_other;
    }

    @Override
    protected void setData() {

    }

    @Override
    protected void init(Bundle inBundle) {
        ButterKnife.bind(this);
        QMUIStatusBarHelper.setStatusBarLightMode(this);
        title.getLeft_ibtn().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        title.getRight_tv().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getInformation();
            }
        });

        mOptionsPickerView = new OptionsPickerView<>(this);

        MarriageList.add("未婚");
        MarriageList.add("已婚");
        ChildrenList.add("有");
        ChildrenList.add("无");
        CurrencyList.add("是");
        CurrencyList.add("否");
        ZodiacyList.add("鼠");
        ZodiacyList.add("牛");
        ZodiacyList.add("虎");
        ZodiacyList.add("兔");
        ZodiacyList.add("龙");
        ZodiacyList.add("蛇");
        ZodiacyList.add("马");
        ZodiacyList.add("羊");
        ZodiacyList.add("猴");
        ZodiacyList.add("鸡");
        ZodiacyList.add("狗");
        ZodiacyList.add("猪");

        getPersonal();
    }

    public void getPersonal() {
        UserNetWorks.getMeData("aa", new Subscriber<ＭeBean>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {
                e.printStackTrace();
                JUtils.Toast("网络错误");
            }

            @Override
            public void onNext(ＭeBean ｍeBean) {
                if (ｍeBean.getResponseState().equals("1")) {
                    if (!CheckUtils.isEmpty(ｍeBean.getData().getHeight())) {
                        TextHeight.setText(ｍeBean.getData().getHeight());
                    }
                    if (!CheckUtils.isEmpty(ｍeBean.getData().getMonthincome())) {
                        TextMonthincome.setText(ｍeBean.getData().getMonthincome());
                    }
                    if (!CheckUtils.isEmpty(ｍeBean.getData().getWeight())) {
                        TextWeight.setText(ｍeBean.getData().getWeight());
                    }
                    if (!CheckUtils.isEmpty(ｍeBean.getData().getSmoke())) {
                        TextSmoke.setText(ｍeBean.getData().getSmoke());
                    }
                    if (!CheckUtils.isEmpty(ｍeBean.getData().getDrinkwine())) {
                        TextDrinkwine.setText(ｍeBean.getData().getDrinkwine());
                    }
                    if (!CheckUtils.isEmpty(ｍeBean.getData().getSymbolicanimals())) {
                        TextSymbolicanimals.setText(ｍeBean.getData().getSymbolicanimals());
                    }
                    if (!CheckUtils.isEmpty(ｍeBean.getData().getReligion())) {
                        TextReligion.setText(ｍeBean.getData().getReligion());
                    }
                }
            }
        });
    }

    @OnClick({R.id.Text_Smoke, R.id.Text_Drinkwine, R.id.Text_Symbolicanimals, R.id.Text_Religion})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.Text_Smoke:
                selectOption(CurrencyList, TextSmoke);
                break;
            case R.id.Text_Drinkwine:
                selectOption(CurrencyList, TextDrinkwine);
                break;
            case R.id.Text_Symbolicanimals:
                selectOption(ZodiacyList, TextSymbolicanimals);
                break;
            case R.id.Text_Religion:
                break;
        }
    }

    public void getInformation() {
        UserNetWorks.getInformation(TextHeight.getText().toString(), TextMonthincome.getText().toString(), TextWeight.getText().toString(), TextSmoke.getText().toString(), TextDrinkwine.getText().toString(), TextSymbolicanimals.getText().toString(), TextReligion.getText().toString(), new Subscriber<VerificationBean>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {
                e.printStackTrace();
                JUtils.Toast("网络错误");
            }

            @Override
            public void onNext(VerificationBean verificationBean) {
                if (verificationBean.getResponseState().equals("1")) {
                    JUtils.Toast(verificationBean.getMsg());
                    finish();
                } else {
                    JUtils.Toast(verificationBean.getMsg());
                }
            }
        });
    }

    public void selectOption(final ArrayList<String> list, final TextView textView) {
        mOptionsPickerView = new OptionsPickerView<>(this);
        // 设置数据
        mOptionsPickerView.setPicker(list);
        // 设置选项单位
        mOptionsPickerView.setOnOptionsSelectListener(new com.airsaid.pickerviewlibrary.OptionsPickerView.OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int option1, int option2, int option3) {
                String sex = list.get(option1);
                textView.setText(sex);
            }
        });
        mOptionsPickerView.show();
    }
}
